﻿using System;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using O1.Storage;

namespace Tests.O1.Storage
{
    [TestClass]
    public class MultiVersionStoreTests
    { 
        //[TestMethod]
        //public void StorageCanReadCommittedVersionWhenTxSkipsAbortedValues()
        //{
        //    var txWatermark = 0;
        //    var data = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 };

        //    var store = new MultiVersionStore(24);
        //    var ix41 = store.Add(data, 1);
        //    store.Prepare(ix41, 1);
        //    store.Commit(ix41, 1);
        //    txWatermark = 1;
        //    data[0] = 255;
        //    store.Write(ix41, data, 2);

        //    // 2 aborts implicitly by not committing, and 3 is allowed to commit, advancing the global watermark:
        //    var ix43 = store.Add(new byte[] { 5, 4, 2, 3, 4, 5, 6, 7 }, 3);
        //    store.Prepare(ix43, 3);
        //    store.Commit(ix43, 3);
        //    txWatermark = 3;

        //    store.Read(ix41, int.MaxValue, txWatermark).Should().NotBeNull();
        //}

        //[TestMethod]
        //public void StorageGCHandlesOutOfOrderMultiplePendingRowsAsExpected()
        //{
        //    // set up: add 3 pending rows out of order...commit in order and read (write - write conflict)
        //    var data = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 };

        //    var store = new MultiVersionStore(24);
        //    var ix41 = store.Add(data, 1);
        //    data[0] = 255;
        //    store.Write(ix41, data, 3);

        //    data[0] = 127;

        //    // This write is ignored, and the returned version is of the later transaction:
        //    var result = store.Write(ix41, data, 2);
        //    result.Should().Be(3);

        //    store.Commit(ix41, 1);
        //    store.Commit(ix41, 2);
        //    store.Read(ix41, 2, 2);

        //    store.Commit(ix41, 3);

        //    var cell = store.Read(ix41, 3, 3);
        //    cell.Should().NotBeNull();
        //    cell[0].Should().Be(255);
        //}
    }
}
